package com.example.activitysign.controller;

import com.example.activitysign.pages.AjaxResult;
import com.example.activitysign.pages.PageResult;
import com.example.activitysign.pages.PageValidate;
import com.example.activitysign.service.IActivityTaskItemService;
import com.example.activitysign.validate.ActivityTaskItemCreateValidate;
import com.example.activitysign.validate.ActivityTaskItemSearchValidate;
import com.example.activitysign.validate.ActivityTaskItemUpdateValidate;
import com.example.activitysign.vo.activity.ActivityTaskItemDetailVo;
import com.example.activitysign.vo.activity.ActivityTaskItemListedVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 任务列管理
 */
@Slf4j
@RestController
@RequestMapping("api/activityTaskItem")
public class ActivityTaskItemController {

    @Resource
    private IActivityTaskItemService iActivityTaskItemService;

    @RequestMapping("/list")
    public AjaxResult<PageResult<ActivityTaskItemListedVo>> list(@Validated PageValidate pageValidate,
                                                                 @Validated @RequestBody ActivityTaskItemSearchValidate searchValidate) {
        PageResult<ActivityTaskItemListedVo> list = iActivityTaskItemService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    public AjaxResult<ActivityTaskItemDetailVo> detail(@Validated @RequestParam("id") Long id) {
        ActivityTaskItemDetailVo detail = iActivityTaskItemService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 任务列新增
     *
     * @param createValidate
     * @return
     */
    @PostMapping("/add")
    public AjaxResult<Object> add(@Validated @RequestBody ActivityTaskItemCreateValidate createValidate) {
        iActivityTaskItemService.add(createValidate);
        return AjaxResult.success();
    }

    /**
     * 任务列编辑
     *
     * @param updateValidate
     * @return
     */
    @PostMapping("/edit")
    public AjaxResult<Object> edit(@Validated @RequestBody ActivityTaskItemUpdateValidate updateValidate) {
        iActivityTaskItemService.edit(updateValidate);
        return AjaxResult.success();
    }


}
